home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.03 Mar 91 / PICS Code / PICS Player Source < prev    next >
Encoding:
Text File  |  1990-12-05  |  3.7 KB  |  179 lines  |  [TEXT/AOqc]

  1. {    PICS Player    -    Steve Sheets}
  2. {}
  3. {    This Progam displays a PICS animation sequence.  It loads PICS files,}
  4. {    animates the file once or animates it in a continous loop.  Either}
  5. {    animation can be canceled by pressing any key.  The program uses}
  6. {    alerts to prompt the user for actions.  The actual animation is drawn}
  7. {    in a window the size of the screen.}
  8.  
  9. program PICSplayer;
  10.  
  11.     uses
  12.         PICSUnit;
  13.  
  14.     const
  15.         kLoadQuit = 500;
  16.         kPICSinfo = 501;
  17.         kError = 502;
  18.         kColorProblem = 503;
  19.  
  20.     var
  21.         gDone, gColorFlag: BOOLEAN;
  22.         gName: Str255;
  23.         gNum: INTEGER;
  24.         gPICS: TPICSHdl;
  25.         gWindow: WindowPtr;
  26.  
  27.     procedure SetUp;
  28.         const
  29.             ROM85Loc = $28E;
  30.             TwoHighMask = $C000;
  31.         type
  32.             WordPtr = ^INTEGER;
  33.         var
  34.             tempWordPtr: WordPtr;
  35.     begin
  36.         tempWordPtr := POINTER(ROM85Loc);
  37.         gColorFlag := (BitAnd(tempWordPtr^, TwoHighMask) = 0);
  38.         gDone := FALSE;
  39.         gName := '';
  40.         gPICS := nil;
  41.         if gColorFlag then
  42.             gWindow := NewCWindow(nil, Screenbits.Bounds, '', TRUE, dBoxProc, POINTER(-1), FALSE, 0)
  43.         else
  44.             gWindow := NewWindow(nil, Screenbits.Bounds, '', TRUE, dBoxProc, POINTER(-1), FALSE, 0);
  45.         if gWindow <> nil then
  46.             begin
  47.                 SetPort(gWindow);
  48.                 EraseRect(screenbits.bounds);
  49.             end;
  50.         SetCursor(Arrow);
  51.     end;
  52.  
  53.     procedure ShutDown;
  54.     begin
  55.         if gPICS <> nil then
  56.             begin
  57.                 DisposePICS(gPICS);
  58.                 gPICS := nil;
  59.             end;
  60.         if gWindow <> nil then
  61.             begin
  62.                 DisposeWindow(gWindow);
  63.                 gWindow := nil;
  64.             end;
  65.     end;
  66.  
  67.     procedure PlayPICS (Loop: BOOLEAN);
  68.         var
  69.             tempH, tempV: INTEGER;
  70.     begin
  71.         if gPICS <> nil then
  72.             begin
  73.                 SelectWindow(gWindow);
  74.                 SetPort(gWindow);
  75.  
  76.                 EraseRect(screenbits.bounds);
  77.                 with screenbits.bounds, gPICS^^ do
  78.                     begin
  79.                         tempH := (right - left - DimH) div 2;
  80.                         tempV := (bottom - top - DimV) div 2;
  81.                         if tempH < 0 then
  82.                             tempH := 0;
  83.                         if tempV < 0 then
  84.                             tempV := 0;
  85.                     end;
  86.  
  87.                 HideCursor;
  88.                 DrawPICS(gPICS, tempH, tempV, Loop, TRUE);
  89.                 ShowCursor;
  90.  
  91.                 EraseRect(screenbits.bounds);
  92.             end;
  93.     end;
  94.  
  95.     procedure LoadPICS;
  96.         var
  97.             tempList: SFTypeList;
  98.             tempPt: Point;
  99.             tempE: OSErr;
  100.             tempStr: Str255;
  101.             tempNum: INTEGER;
  102.             tempReply: SFReply;
  103.     begin
  104.         if gPICS <> nil then
  105.             begin
  106.                 DisposePICS(gPICS);
  107.                 gPICS := nil;
  108.             end;
  109.  
  110.         tempPt.v := 40;
  111.         tempPt.h := 40;
  112.         tempList[0] := kPICStype;
  113.         SFGetFile(tempPt, '', nil, 1, tempList, nil, tempReply);
  114.         if tempReply.good then
  115.             begin
  116.                 gName := tempReply.fname;
  117.                 tempE := ReadPICS(gName, tempReply.vRefNum, gPICS);
  118.                 if tempE <> noErr then
  119.                     begin
  120.                         case tempE of
  121.                             memFullErr: 
  122.                                 tempStr := 'Memmory full error.  The file you are reading is to large';
  123.                             fnfErr: 
  124.                                 tempStr := 'File not found error';
  125.                             resNotFound: 
  126.                                 tempStr := 'A required resource was not found in the file';
  127.                             otherwise
  128.                                 begin
  129.                                     NumToString(tempE, tempStr);
  130.                                     tempStr := CONCAT('Error Number: ', tempStr);
  131.                                 end
  132.                         end;
  133.                         ParamText(gName, tempStr, '', '');
  134.                         tempNum := Alert(kError, nil);
  135.                     end
  136.                 else if (not gColorFlag) and (gPICS <> nil) then
  137.                     if (gPICS^^.PICSInfoHdl <> nil) then
  138.                         if (gPICS^^.PICSInfoHdl^^.BWColor = 1) then
  139.                             begin
  140.                                 ParamText(gName, '', '', '');
  141.                                 tempNum := Alert(kColorProblem, nil);
  142.                             end;
  143.             end;
  144.     end;
  145.  
  146.     procedure DoInformationAlert;
  147.         var
  148.             tempStr: Str255;
  149.     begin
  150.         NumToString(gPICS^^.NumFrames, tempStr);
  151.         ParamText(gName, tempStr, '', '');
  152.         gNum := Alert(kPICSinfo, nil);
  153.     end;
  154.  
  155. begin
  156.     SetUp;
  157.  
  158.     if gWindow <> nil then
  159.         repeat
  160.             if gPICS = nil then
  161.                 gNum := Alert(kLoadQuit, nil)
  162.             else
  163.                 DoInformationAlert;
  164.  
  165.             case gNum of
  166.                 1: 
  167.                     PlayPICS(FALSE);
  168.                 2: 
  169.                     LoadPICS;
  170.                 3: 
  171.                     gDone := TRUE;
  172.                 4: 
  173.                     PlayPICS(TRUE);
  174.                 otherwise
  175.             end;
  176.         until gDone;
  177.  
  178.     ShutDown;
  179. end.